import json
import yaml
import os


def load_json_file(path):
    content = ''
    with open(path, 'rb') as f:
        line = f.readline()
        while line:
            content += line.decode()
            line = f.readline()
    return json.loads(content)


def load_yaml_file(path):
    assert os.path.isfile(path), '"{}"文件不存在'.format(path)
    with open(path, 'r', encoding='utf-8') as f:
        content = f.read()
    return yaml.load(content)


def dump_yaml_file(path, data):
    with open(path, 'w+', encoding='utf-8') as f:
        yaml.dump(data, f, default_flow_style=False, encoding="utf-8", allow_unicode=True)
